import java.sql.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

public class EditUser extends HttpServlet
{
    public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException,IOException
    {
		doPost(request,response);
	}//doGet

    public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException,IOException
    {
		RequestDispatcher dispatcher = null;
		try
		{
			HttpSession session = request.getSession();
			String id1 = (String)session.getAttribute("id");
			int id = Integer.parseInt(id1);
			String username = request.getParameter("username");
			String pwd = request.getParameter("password");
			String first = request.getParameter("first");
			String last = request.getParameter("last");
			String mobno = request.getParameter("mobno");
			int salary = Integer.parseInt(request.getParameter("salary"));
			int utype = Integer.parseInt(request.getParameter("utype"));
			Class.forName("com.mysql.jdbc.Driver").newInstance();
			Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/airtel","root","root");
			Statement stmt = con.createStatement();
			String qry = "update users set userName='"+username+"',password='"+pwd+"',first='"+first+"',last='"+last+"',mobile='"+mobno+"',salary='"+salary+"',authType='"+utype+"' where id="+id+"";
			System.out.println("Update Query is:"+qry);
			int value = stmt.executeUpdate(qry);
			if(value==1)
			{
				System.out.println("User Updated succesfully");
				request.setAttribute("msg", new String("User Details Updated succesfully"));
				dispatcher = getServletContext().getRequestDispatcher("/jsp/EditUser1.jsp");
				dispatcher.forward(request,response);
			}
        }//try
		catch(Exception e)
		{
            e.printStackTrace();
		}//catch
	}//doPost
}//class